flutter check if string is number

96

bool isNumeric(String s) {
 if (s == null) {
   return false;
 }
 return double.tryParse(s) != null;
}
void main() {
  var stringArr = ["Hello world", "Hello1 World", "H23llo", "H00Elo", "World"];

  for (var i = 0; i < stringArr.length; i++) {
    bool found = stringArr[i].contains(new RegExp(r'[0-9]'));
    print(stringArr[i] + " -> " + found.toString());
  }
}

Comments

Submit
0 Comments